package src.com.java.dtgh.twoDay;

import java.util.Scanner;

public class demo2 {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int space = sc.nextInt();

        int[] weight = new int[n];
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            weight[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            value[i] = sc.nextInt();
        }
        int[] solve = solve(weight, value, space);

        System.out.println(solve[space + 1]);


    }

    public static int[] solve(int[] weight,int[] value,int space){

        int[] dp = new int[space + 1];

        for (int i = 0; i < dp.length; i++) {
            dp[i] = 0;
        }
        int len = weight.length;

        for(int i = 0;i < len;i++){
            for(int j = space;j >= weight[i];j--){
                dp[j] = Math.max(dp[j],dp[j - weight[i]] + value[i]);
            }
        }
        return dp;
    }
}
